<template>
  <div class="level">
     <h1>医院</h1>
    <div class="content">
      <div class="left">等级:</div>
      <ul class="hospital">
        <li
          :class="{active : activeFlag === ''}"
          @click="levelChange('')"
        >全部</li>
        <li
          v-for="(item, index) in levelList"
          :key="item.value"
          :class="{ active : activeFlag === item.value }"
          @click="levelChange(item.value)"
        >{{ item.name }}</li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref} from "vue";
import {HospitalLevelAndRegionArr, HospitalLevelAndRegionResponseData} from "@/api/home/type";
import { reqHospitalLevelAndRegion } from "@/api/home";

let levelList = ref<HospitalLevelAndRegionArr>([])

let activeFlag = ref<string>('')
onMounted(() => {
  getHospitalLevel()
})
const getHospitalLevel = async () => {
  const result: HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion('HosType')
  if (result.code === 200) {
    levelList.value = result.data
  }
}

const levelChange = (value: string) => {
  activeFlag.value = value
  $emit('getLevel', value)
}
let $emit = defineEmits([
    'getLevel'
])
</script>

<script lang="ts">
export default {
  name: 'Level'
}
</script>

<style scoped lang="scss">
.level {
  color: #7f7f7f;
  h1 {
    font-weight: 900;
    margin: 10px 0;
  }
  .content {
    display: flex;
    .left {
      margin-right: 10px;
    }
    .hospital {
      display: flex;
      li {
        margin-right: 10px;
        &.active {
          color: #55a6fe;
        }
        &:hover {
          color: #55a6fe;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
